package stsj.meddroid.elements;

import stsj.meddroid.Resources;
import stsj.meddroid.screen.BattleScreen;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;

public class RedRepetol extends Enemy{
	private int state;
	private int count;
	private int counter;
	private int repetolX;
	private int repetolY;
	public static int se;
	public static int ye;
	public static boolean isRedBertelur;
	public RedRepetol(int x, int y) {
		super(20, Enemy.REDREPETOL, x, y, BattleScreen.texRedRepetol);
		// TODO Auto-generated constructor stub
		mySprite = new Sprite(BattleScreen.texRedRepetol,5,5,52,52);
		mySprite.setSize(52, 52);
		mySprite.setPosition(x, y);
		mySprite.setRegion(5, 5, 52, 52);
		myRectangle = new Rectangle(x,y,mySprite.getWidth(),mySprite.getHeight());
		isRedBertelur = false;
		state = 0;
		count = 0;
		counter = 0;
		repetolX = x;
		repetolY = y;
		se = repetolX;
		ye = repetolY;
	}
	
	public void laySlime(){
		// Sprite temp;
		//if (face == Enemy.LEFT) {
		//							arrEnemy.add(new RedSlime(x-30,y-60))
		//							temp = new Sprite(texRedSlime,0,0,32,32);
		//							temp.setPosition(x-30,y-60);
		//							arrSprite.add(temp);
		//							arrRec.add(new Rectangle(x-30,y-60,32,32));
		//							};
		//else (face == Enemy.RIGHT) {
		//							arrEnemy.add(new RedSlime(x+90,y-60))
		//							temp = new Sprite(texRedSlime,0,0,32,32);
		//							temp.setPosition(x+90,y-60);
		//							arrSprite.add(temp);
		//							arrRec.add(new Rectangle(x+90,y-60,32,32));
		//							};
	}	
	
	public void lasered(){
		super.lasered(25);
	}
	
	public void damaged(){
		super.damaged(2);
	}
	
	public void dropOrb(){
		super.dropOrb(33);
	}
	
	public void moveRight(){
		super.moveRight();
		se = x;
		state++;
		mySprite.setScale(1, 1);
		mySprite.setRegion((state%2)*64+5, 5, 52, 52);
	}
	
	public void moveLeft(){
		super.moveLeft();
		state++;
		ye = y;
		mySprite.setRegion((state%2)*64+5, 5, 52, 52);
		mySprite.setScale(-1, 1);
		if(state == 60) {state = 0;}
	}
	
	public void autoMove(){
		if (count != 4) {count++;}
		else{
			if (state < 30){				
				face = RIGHT;
				moveRight();
			}
			else{
				face = LEFT;
				moveLeft();
			}
			counter++;
			count = 0;
			
			if (counter == 200) {
				isRedBertelur = true;
				counter = 0;
			}
		}
		
	}
	
	public static void addEnemySlime() {
		BattleScreen.listOfEnemies.put(new GomuKing(se+50,ye),false);
		System.out.println("Sampai sini");
		Resources.playSound(Resources.petelurSound);
		
	}
	
	public static boolean isIntersectMedDroid(){
		int temp = se+ 50;
		while (temp <= se + 90){
			if (temp >= BattleScreen.medDroid.x && temp <= BattleScreen.medDroid.x+24){
				int temp2 = ye;
				while (temp2 <= ye + 90){
					if (temp >= BattleScreen.medDroid.y && temp <= BattleScreen.medDroid.y+40){return true;}
				}
			}
			else {temp++;}
		}
		return false;
	}
}
